﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Hadron.License
{
    public partial class LicenseForm : Form
    {
        private bool m_bValidKey;
        private String m_strKey;

        public LicenseForm()
        {
            InitializeComponent();
        }

        private void m_btnDemo_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            Close();
        }

        private void m_btnUnlock_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            Close();
        }

        private void m_btnBuy_Click(object p_objSender, EventArgs p_eventArgs)
        {
            try
            {
                System.Diagnostics.Process.Start("http://www.sharkbaitgames.com");
            }
            catch (Exception)
            {
                MessageBox.Show(null,
                    "An error occured while attempting to open a browser window.",
                    "Buy Now", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void m_txtKey_TextChanged(object p_objSender, EventArgs p_eventArgs)
        {
            m_btnUnlock.Enabled = LicenseManager.Instance.IsValidKey(m_txtKey.Text);
            m_btnDemo.Enabled = m_btnBuy.Enabled = !m_btnUnlock.Enabled;
            m_bValidKey = m_btnUnlock.Enabled;
            if (m_bValidKey)
                m_strKey = m_txtKey.Text;
            else
                m_strKey = "";
        }

        public bool ValidKey
        {
            get { return m_bValidKey; }
        }

        public String LicenseKey
        {
            get { return m_strKey; }
        }
    }
}
